﻿using System;
using TIS.DAO;
using System.Data;

namespace TIS.NewsTis
{
    public partial class TisNews : System.Web.UI.Page
    {
        
        NewsDAO _newsDao = new NewsDAO();
        SettingDAO _settingDao = new SettingDAO();
        CategoryDAO _categoryDao = new CategoryDAO();

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                if (Session["lang"] == null)
                {
                    Session["lang"] = 1;
                }
                BindContent();
            }

        }

        public void BindContent()
        {
            string id = Request.QueryString["id"];
            int langId = int.Parse(Session["lang"].ToString());
            if (id != null)
            {
                
                DataTable dt = _newsDao.GetContent(int.Parse(id), langId);
                foreach (DataRow rows in dt.Rows)
                {
                    ltlMetaTitle.Text = rows["NewsMetaTitle"].ToString();
                    ltlMetaDescription.Text = rows["NewsMetaDescription"].ToString();
                    ltlMetaKeywords.Text = rows["NewsMetaKeyword"].ToString();
                    int categoryId = int.Parse(rows["CategoryId"].ToString());
                    ltlImageCategory.Text = rows["CategoryImage"].ToString() == "" ? "<img src=\"/images/baner-product.jpg\" width=\"980\" height=\"280\" alt=\"Banner\" />" : "<img src=\"" + rows["CategoryImage"].ToString() + "\" width=\"980\" height=\"280\" alt=\"Banner\" />";
                    ltlDisplayProject.Text = rows["CategorySEOUrl"].ToString().Substring(0, 4) == "http" ? "none" : "block";
                    
                    rpContent.DataSource = dt;
                    rpContent.DataBind();

                    rpTinTrienKhai.DataSource = _newsDao.GetTinKhacTisNews(categoryId, int.Parse(id), langId, rows["NewsDate"].ToString());
                    rpTinTrienKhai.DataBind();
                }

                ltlFacebook.Text = _settingDao.GetValue("facebook", int.Parse(Session["lang"].ToString()));
                ltlGoogle.Text = _settingDao.GetValue("googleplus", int.Parse(Session["lang"].ToString()));
            }

        }
    }
}